class Request {
    constructor() {
        this.baseUrl = 'http://47.121.118.187:7788';
        this.timeout = 5000;
    }
    request(options) {
        return new Promise((resolve, reject) => {
            const showLoading = options.opts.showLoading !== false;
            showLoading && uni.showLoading({ title: '加载中' });
            uni.request({
                url: this.baseUrl + options.url,
                method: options.method || 'GET',
                data: options.data || {},
                timeout: this.timeout,
                success: (res) => {
                    if (res.data.code === 200) {
                        resolve(res.data);
                    } else {
                        reject(res);
                    }
                },
                fail: (err) => {
                    reject(err);
                },
                complete: () => {
                    uni.hideLoading();
                }
            })
        })
    }
    get(url, data = {}, opts = {}) {
        return this.request({
            url,
            data,
            opts,
            method: 'GET',
        })
    }
    post(url, data = {}, opts = {}) {
        return this.request({
            url,
            data,
            opts,
            method: 'POST',
        })
    }
}

export default new Request();